﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Str2SbCollection
{
    public partial class frmdouhao : Form
    {
        public frmdouhao()
        {
            InitializeComponent();
        }



        protected string SplitForDataReader(string source,string objName)
        {
            string result=string.Empty;
            string[] splitStr = source.Split(',');
            for (int i = 0; i < splitStr.Length; i++)
            {
                if (splitStr[i].Trim() == string.Empty)
                    continue;
                string resultMethodddd = "if (dataReader[" + i + "]!=null)\n";
                resultMethodddd += "{\n";
                resultMethodddd += "    " + objName + "." + splitStr[i] + " = " + "dataReader[" + i + "].ToString();\n";
                resultMethodddd += "}\n";
                result += resultMethodddd;
            }
            return result;
        }

        protected string SplitForTable(string source, string objName)
        {
            string result = string.Empty;
            string[] splitStr = source.Split(',');
            for (int i = 0; i < splitStr.Length; i++)
            {
                if (splitStr[i].Trim() == string.Empty)
                    continue;
                string resultMethodddd = "if (row[\"" + splitStr[i] + "\"]!=null)\n";
                resultMethodddd += "{\n";
                resultMethodddd += "    " + objName + "." + splitStr[i] + " = " + "row[\"" + splitStr[i] + "\"].ToString();\n";
                resultMethodddd += "}\n";
                result += resultMethodddd;
            }
            return result;
        }

        protected string SplitForReaderName(string source, string objName)
        {
            string result = string.Empty;
            string[] splitStr = source.Split(',');
            for (int i = 0; i < splitStr.Length; i++)
            {
                if (splitStr[i].Trim() == string.Empty)
                    continue;
                string resultMethodddd = "if (dataReader[\"" + splitStr[i] + "\"]!=null)\n";
                resultMethodddd += "{\n";
                resultMethodddd += "    " + objName + "." + splitStr[i] + " = " + "dataReader[\"" + splitStr[i] + "\"].ToString();\n";
                resultMethodddd += "}\n";
                result += resultMethodddd;
            }
            return result;
        }

        private void btnReader_Click(object sender, EventArgs e)
        {
            txtResult.Text = string.Empty;
            string source = txtSource.Text;
            string result = this.SplitForDataReader(source, txtObjName.Text);
            txtResult.Text = result;
        }

        private void btnTable_Click(object sender, EventArgs e)
        {
            txtResult.Text = string.Empty;
            string source = txtSource.Text;
            string result = this.SplitForTable(source, txtObjName.Text);
            txtResult.Text = result;
        }

        private void txtSource_Click(object sender, EventArgs e)
        {
            txtSource.SelectAll();
        }

        private void btnReader4Name_Click(object sender, EventArgs e)
        {
            txtResult.Text = string.Empty;
            string source = txtSource.Text;
            string result = this.SplitForReaderName(source, txtObjName.Text);
            txtResult.Text = result;
        }
    }
}
